package com.kawaiior.asoulworld.capability;

import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager;


public class CapabilityRegistryHandler {

    public static void register(){

        // AvaPower 向晚盔甲
        CapabilityManager.INSTANCE.register(AvaPower.class, new Capability.IStorage<AvaPower>(){
            @Override
            public NBTBase writeNBT(Capability<AvaPower> capability, AvaPower instance, EnumFacing side) {
                return instance.serializeNBT();
            }

            @Override
            public void readNBT(Capability<AvaPower> capability, AvaPower instance, EnumFacing side, NBTBase nbt) {
                instance.deserializeNBT((NBTTagCompound)nbt);
            }
        }, AvaPower::new);

        // MiyuWand 蓝宝石之星
        CapabilityManager.INSTANCE.register(MiyuPower.class, new Capability.IStorage<MiyuPower>(){
            @Override
            public NBTBase writeNBT(Capability<MiyuPower> capability, MiyuPower instance, EnumFacing side) {
                return instance.serializeNBT();
            }

            @Override
            public void readNBT(Capability<MiyuPower> capability, MiyuPower instance, EnumFacing side, NBTBase nbt) {
                instance.deserializeNBT((NBTTagCompound)nbt);
            }
        }, MiyuPower::new);

        // solo剑的效果
        CapabilityManager.INSTANCE.register(AsoulAirPower.class, new Capability.IStorage<AsoulAirPower>(){
            @Override
            public NBTBase writeNBT(Capability<AsoulAirPower> capability, AsoulAirPower instance, EnumFacing side) {
                return instance.serializeNBT();
            }

            @Override
            public void readNBT(Capability<AsoulAirPower> capability, AsoulAirPower instance, EnumFacing side, NBTBase nbt) {
                instance.deserializeNBT((NBTTagCompound)nbt);
            }
        }, AsoulAirPower::new);

        // 时间回溯
        CapabilityManager.INSTANCE.register(AsoulTimePower.class, new Capability.IStorage<AsoulTimePower>(){
            @Override
            public NBTBase writeNBT(Capability<AsoulTimePower> capability, AsoulTimePower instance, EnumFacing side) {
                return instance.serializeNBT();
            }

            @Override
            public void readNBT(Capability<AsoulTimePower> capability, AsoulTimePower instance, EnumFacing side, NBTBase nbt) {
                instance.deserializeNBT((NBTTagCompound)nbt);
            }
        }, AsoulTimePower::new);
    }

    @CapabilityInject(AvaPower.class)
    public static Capability<AvaPower> AVA_POWER;

    @CapabilityInject(MiyuPower.class)
    public static Capability<MiyuPower> MIYU_POWER;

    @CapabilityInject(AsoulAirPower.class)
    public static Capability<AsoulAirPower> ASOUL_AIR_POWER;

    @CapabilityInject(AsoulTimePower.class)
    public static Capability<AsoulTimePower> ASOUL_TIME_POWER;
}
